package com.hncc.dms.controller;

import java.util.List;

import com.hncc.common.util.BeanCopierUtil;
import com.hncc.common.vo.dms.DmsDiseCatalogVO;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hncc.dms.domain.DmsDiseCatalog;
import com.hncc.dms.service.IDmsDiseCatalogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 诊断类型（疾病）目录Controller
 * 
 * @author HYJ
 * @date 2020-08-27
 */
@RestController
@RequestMapping("/dms/dise_catalog")
public class DmsDiseCatalogController extends BaseController
{
    @Autowired
    private IDmsDiseCatalogService dmsDiseCatalogService;

    /**
     * 查询诊断类型（疾病）目录列表
     */
    @ApiOperation(value = "查询",notes = "查询目录列表",response = TableDataInfo.class)
    @ApiResponses({
            @ApiResponse(code = 204,message = "操作已经执行成功，但是没有返回数据"),
            @ApiResponse(code = 303,message = "重定向"),
            @ApiResponse(code = 400,message = "参数列表错误（缺少，格式不匹配）"),
            @ApiResponse(code = 500,message = "系统内部错误"),
            @ApiResponse(code = 404,message = "资源，服务未找到"),
            @ApiResponse(code = 200,message = "操作成功"),
            @ApiResponse(code = 401,message = "未授权"),
            @ApiResponse(code = 403,message = "访问受限，授权过期")
    })
    @PreAuthorize("@ss.hasPermi('dms:dise_catalog:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmsDiseCatalogVO dmsDiseCatalogVO)
    {
        startPage();
        //将实体vo转换成 对应的实体
        List<DmsDiseCatalog> list = dmsDiseCatalogService.selectDmsDiseCatalogList(BeanCopierUtil.copy(dmsDiseCatalogVO,DmsDiseCatalog.class));
        // 先获取总行数
        TableDataInfo tableDataInfo = getDataTable(list);
        // 替换 vo 集合
        tableDataInfo.setRows(BeanCopierUtil.copy(list,DmsDiseCatalogVO.class));
        return tableDataInfo;
    }

    /**
     * 导出诊断类型（疾病）目录列表
     */
    @ApiOperation(value = "导出",notes = "导出目录列表",response = AjaxResult.class)
    @ApiResponses({
            @ApiResponse(code = 204,message = "操作已经执行成功，但是没有返回数据"),
            @ApiResponse(code = 303,message = "重定向"),
            @ApiResponse(code = 400,message = "参数列表错误（缺少，格式不匹配）"),
            @ApiResponse(code = 500,message = "系统内部错误"),
            @ApiResponse(code = 404,message = "资源，服务未找到"),
            @ApiResponse(code = 200,message = "操作成功"),
            @ApiResponse(code = 401,message = "未授权"),
            @ApiResponse(code = 403,message = "访问受限，授权过期")
    })
    @PreAuthorize("@ss.hasPermi('dms:dise_catalog:export')")
    @Log(title = "诊断类型（疾病）目录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DmsDiseCatalogVO dmsDiseCatalogVO)
    {
        List<DmsDiseCatalog> list = dmsDiseCatalogService.selectDmsDiseCatalogList(BeanCopierUtil.copy(dmsDiseCatalogVO, DmsDiseCatalog.class));
        ExcelUtil<DmsDiseCatalogVO> util = new ExcelUtil<DmsDiseCatalogVO>(DmsDiseCatalogVO.class);
        List<DmsDiseCatalogVO> vos = BeanCopierUtil.copy(list,DmsDiseCatalogVO.class);
        return util.exportExcel(vos, "diseCatalog");
    }

    /**
     * 获取诊断类型（疾病）目录详细信息
     */
    @ApiOperation(value = "详细信息",notes = "根据目录Id获取目录详情",response = AjaxResult.class)
    @ApiResponses({
            @ApiResponse(code = 204,message = "操作已经执行成功，但是没有返回数据"),
            @ApiResponse(code = 303,message = "重定向"),
            @ApiResponse(code = 400,message = "参数列表错误（缺少，格式不匹配）"),
            @ApiResponse(code = 500,message = "系统内部错误"),
            @ApiResponse(code = 404,message = "资源，服务未找到"),
            @ApiResponse(code = 200,message = "操作成功"),
            @ApiResponse(code = 401,message = "未授权"),
            @ApiResponse(code = 403,message = "访问受限，授权过期")
    })
    @PreAuthorize("@ss.hasPermi('dms:dise_catalog:query')")
    @GetMapping(value = "/{id}")
    @ApiParam(value = "目录id",name ="id" ,defaultValue = "1",required = true)
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(BeanCopierUtil.copy(dmsDiseCatalogService.selectDmsDiseCatalogById(id),DmsDiseCatalog.class));
    }

    /**
     * 新增诊断类型（疾病）目录
     */
    @ApiOperation(value = "新增",notes = "新增一个目录,id可以不用输入",response = AjaxResult.class)
    @ApiResponses({
            @ApiResponse(code = 204,message = "操作已经执行成功，但是没有返回数据"),
            @ApiResponse(code = 303,message = "重定向"),
            @ApiResponse(code = 400,message = "参数列表错误（缺少，格式不匹配）"),
            @ApiResponse(code = 500,message = " 系统内部错误"),
            @ApiResponse(code = 404,message = " 资源，服务未找到"),
            @ApiResponse(code = 200,message = " 操作成功")
    })
    @ApiParam(value = "DmsDiseCatalogVO", name ="诊断目录对象VO",type = "DmsDiseCatalogVO")
    @PreAuthorize("@ss.hasPermi('dms:dise_catalog:add')")
    @Log(title = "诊断类型（疾病）目录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsDiseCatalogVO dmsDiseCatalogVO)
    {
        return toAjax(dmsDiseCatalogService.insertDmsDiseCatalog(BeanCopierUtil.copy(dmsDiseCatalogVO,DmsDiseCatalog.class)));
    }

    /**
     * 修改诊断类型（疾病）目录
     */
    @ApiOperation(value = "修改",notes = "修改目录,id必须输入",response = AjaxResult.class)
    @ApiResponses({
            @ApiResponse(code = 204,message = "操作已经执行成功，但是没有返回数据"),
            @ApiResponse(code = 303,message = "重定向"),
            @ApiResponse(code = 400,message = "参数列表错误（缺少，格式不匹配）"),
            @ApiResponse(code = 500,message = " 系统内部错误"),
            @ApiResponse(code = 404,message = " 资源，服务未找到"),
            @ApiResponse(code = 200,message = " 操作成功")
    })
    @ApiParam(value = "DmsDiseCatalogVO", name ="诊断目录对象VO",type = "DmsDiseCatalogVO")
    @PreAuthorize("@ss.hasPermi('dms:dise_catalog:edit')")
    @Log(title = "诊断类型（疾病）目录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsDiseCatalogVO dmsDiseCatalogVO)
    {
        return toAjax(dmsDiseCatalogService.updateDmsDiseCatalog(BeanCopierUtil.copy(dmsDiseCatalogVO,DmsDiseCatalog.class)));
    }

    /**
     * 删除诊断类型（疾病）目录
     */
    @ApiOperation(value = "删除",notes = "根据目录id删除目录",response = AjaxResult.class)
    @ApiResponses({
            @ApiResponse(code = 204,message = "操作已经执行成功，但是没有返回数据"),
            @ApiResponse(code = 303,message = "重定向"),
            @ApiResponse(code = 400,message = "参数列表错误（缺少，格式不匹配）"),
            @ApiResponse(code = 500,message = " 系统内部错误"),
            @ApiResponse(code = 404,message = " 资源，服务未找到"),
            @ApiResponse(code = 200,message = " 操作成功")
    })
    @ApiParam(value = "ids,目录id可以是数组。删除时目录内的疾病都会被删除。",name ="ids" ,defaultValue = "1",required = true)
    @PreAuthorize("@ss.hasPermi('dms:dise_catalog:remove')")
    @Log(title = "诊断类型（疾病）目录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dmsDiseCatalogService.deleteDmsDiseCatalogByIds(ids));
    }
}
